package icu.qx.diagram.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import icu.qx.diagram.domain.Drawback;
import icu.qx.diagram.domain.MaterialOutbound;
import icu.qx.diagram.service.IDrawbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

@RestController
@RequestMapping("/diagram/drawback")
public class DrawbackController extends  BaseController{
    private final IDrawbackService drawbackService;
    @Autowired
    public DrawbackController(IDrawbackService drawbackService){this.drawbackService=drawbackService;}
    /**
     * 查询缺陷统计
     */
    @RequiresPermissions("diagram:drawback:list")
    @GetMapping("/list")
    public TableDataInfo list(Drawback drawback)
    {
        startPage();
        List<Drawback> list=drawbackService.selectDrawbackList(drawback);
        for(Drawback d:list){
            d.setCreatorName(SecurityUtils.getUsername());
        }
        return getDataTable(list);
    }
    /**
     * 导出缺陷统计
     */
    @RequiresPermissions("diagram:drawback:export")
    @Log(title = "缺陷统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Drawback drawback) {
        List<Drawback> list = drawbackService.selectDrawbackList(drawback);
        ExcelUtil<Drawback> util = new ExcelUtil<>(Drawback.class);
        util.exportExcel(response, list, "缺陷统计数据");
    }
}
